<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <title>机构类型选择</title>

    <!-- Expand styles -->
    <link href="../css/app/app.css" rel="stylesheet">
    <link href="../css/app/default.css" rel="stylesheet">
    <link href="../css/mui/mui.css" rel="stylesheet">
</head>

<body>
    <!-- header -->

    <div class="widget-body widget-default display-flex flex-warp padding-b-15 padding-t-20" id="typeList">
        
    </div>

    <script src="../js/dsbridge.js"></script>
    <script src="../js/jquery.js"></script>
    <script src="../js/mui/mui.js"></script>
    <script src="../js/mui/mui.picker.min.js"></script>
    <script src="../js/layer.js"></script>
    <script src="../js/city.data-3.js"></script>
    <script src="../js/app/app-base.js"></script>
    <script src="../js/app/app-url.js"></script>
    <script src="../js/app/app-ajax.js"></script>
    <script>
        $(document).ready(function(){
            //获取培训类型
            getTrainType();

            dsBridge.register('save', function () {
                save();
            })
        })

        //获取培训类型
        function getTrainType(){
            var data = {
                pCode:'TRAN_TYPE'
            }
            getServerData(url_businessdatamng_queryList, data);
        }

        function getServerDataSuccess(url, data) {
            switch (url) {
                case url_businessdatamng_queryList:
                    //培训类型
                    data = data.data;
                    var orgServiceType = strToJson(localStorage.getItem("orgServiceType"));
                    var serviceTypeCodeList = orgServiceType.serviceTypeCodeList;
                    var h5 = '';
                    if(data != null && data.length > 0){
                        $.each(data,function(index,item){
                            var selectClass = '';
                            if(serviceTypeCodeList != null && serviceTypeCodeList.length > 0 && serviceTypeCodeList.includes(item.code)){
                                selectClass = 'tuli-bg';
                            }
                            h5 += '<span class="tuli-content-label font-15 '+selectClass+'" code="'+item.code+'">'+item.name+'</span>';
                        })
                    }
                    $("#typeList").html(h5);
                    break;
                case url_trandemandmgr_save:
                    //保存
                    //信息框
                    layer.open({
                        content: "发布成功",
                        btn: '确定',
                        shadeClose:false,
                        yes: function (index) {
                            layer.close(index);
                            dsBridge.call("saveClose","");
                        }
                    });
                    break;
                case url_trandemandmgr_queryList:
                    
                    break;
            }
        }

        //选择类型
        $("#typeList").on("tap",".tuli-content-label",function(){
            $(this).toggleClass("tuli-bg");
        })

        //保存
        function save(){
            var serviceTypeCodeList = new Array();
            var serviceTypeNameList = new Array();
            $("#typeList .tuli-content-label").each(function(index,item){
                if($(item).hasClass("tuli-bg")){
                    serviceTypeCodeList.push($(item).attr("code"));
                    serviceTypeNameList.push($(item).text());
                }
            })
            if(serviceTypeCodeList.length <= 0){
                showToast("请选择擅长培训类型");
                return;
            }
            var orgServiceType = {
                "serviceTypeCodeList":serviceTypeCodeList,
                "serviceTypeNameList":serviceTypeNameList
            }
            localStorage.setItem("orgServiceType",toJson(orgServiceType));
            dsBridge.call("save","");
        }
    </script>

</body>

</html>